﻿using Entity;
using Entity.Room;
using Hotel.Models;
using IHotelBLL.IRoomBLL;
using IHotelDAL.IRoomDAL;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace Hotel.Controllers.Room.Type
{
    public class RoomTypeController : Controller
    {
        ResultModel result = new ResultModel();
        IRoomTypeBLL _roomType;
        public RoomTypeController(IRoomTypeBLL roomTypebll)
        {
            _roomType = roomTypebll;
        }
        //[HttpPost]
        //public IActionResult AddRoomType(RoomType roomType)
        //{
        //    if (roomType.TypeName == null)
        //    {
        //        result.Msg = "类型名称不能为空";
        //        return Json(result);
        //    }
        //    result.IsSuccess = _roomType.AddRoomType(roomType, out string msg);
        //    result.Msg = msg;
        //    return Json(result);
        //}
        //public IActionResult RemoveRoomType(string id)
        //{
        //    result.IsSuccess = _roomType.RemoveRoomType(id, out string msg);
        //    result.Msg = msg;
        //    return Json(result);
        //}
        //public IActionResult GetRoomType()
        //{
        //    result.Data = _roomType.GetAllRoomTypes();
        //    return Json(result);
        //}
        //public IActionResult UpdateRoomType(RoomType roomType)
        //{
        //    result.IsSuccess = _roomType.UpdateRoomType(roomType, out string msg);
        //    result.Msg = msg;
        //    return Json(result);
        //}




        public IActionResult GetRoomTypes(int page, int limit, string TypeName)
        {
            List<RoomType> floors = _roomType.GetRoomTypes(page, limit, TypeName, out int count);
            var res = new
            {
                code = 0,
                msg = "",
                count,
                data = floors
            };
            return Json(res);
        }




        public IActionResult AddRoomType(string TypeName)
        {
            //返回对象
            ResultModel res = new ResultModel();
            //参数验证
            if (string.IsNullOrEmpty(TypeName))
            {
                res.Msg = "名称不能为空";
                return Json(res);
            }

            string msg;
            //创建
            bool isSuccess = _roomType.AddRoomType(TypeName, out msg);
            if (isSuccess)
            {
                res.Status = 1;
            }
            res.IsSuccess = isSuccess;
            res.Msg = msg;
            return Json(res);
        }
       
        public IActionResult UpdateRoomType(string id, string TypeName)
        {
            //返回对象
            ResultModel res = new ResultModel();
            if (string.IsNullOrEmpty(id))
            {
                res.Msg = "id不能为空";
                return Json(res);
            }
            if (string.IsNullOrEmpty(TypeName))
            {
                res.Msg = "名称不能为空";
                return Json(res);
            }


            string msg;
            //调用bll修改业务方法
            bool isSuccess = _roomType.UpdateRoomType(id, TypeName, out msg);

            if (isSuccess)
            {
                res.Status = 1;
                res.IsSuccess = true;
            }
            res.Msg = msg;
            return Json(res);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult RemoveRoomType(string id)
        {
            //返回对象
            ResultModel res = new ResultModel();

            if (string.IsNullOrEmpty(id))
            {
                res.Msg = "id不能为空";
                return Json(res);
            }
            //删除业务
            bool isSuccess = _roomType.RemoveRoomType(id, out string msg);
            res.Msg = msg;
            res.IsSuccess = isSuccess;
            if (isSuccess)
            {
                res.Status = 1;
            }
            return Json(res);
        }

       
        public IActionResult GetRoomTypeById(string id)
        {
            //返回对象
            ResultModel res = new ResultModel();
            if (string.IsNullOrEmpty(id))
            {
                res.Msg = "id不能为空";
                return Json(res);
            }

           
            //根据id查信息
            RoomType roomInfo = _roomType.GetRoomTypeById(id);
            if (roomInfo == null)
            {
                res.Msg = "未查询到信息";
                return Json(res);
            }
            res.Data = roomInfo;
          
            res.IsSuccess = true;
            return Json(res);

        }


    }
}
